const puppeteer = require('puppeteer')

const url = 'https://mil.news.sina.com.cn/'

const sleep = time => new Promise(resolve => {
    setTimeout(resolve, time)
})


;
(async() => {

    console.log("开始爬取新浪军事数据")

    const browser = await puppeteer.launch({
        arg: ['--no-sanbox'],
        dumpio: false
    })

    const page = await browser.newPage()

    await page.goto(url, {
        waitUntil: 'networkidle2'
    })

    await sleep(3000)

    const result = await page.evaluate(() => {

        var $ = window.$
        var items = $('.part1.arcticle-list li')
            //part1 arcticle-list
        var links = [];

        if (items.length >= 1) {
            items.each((index, item) => {
                let it = $(item)
                let herf = it.find('a').attr('href')
                let text = it.find('a').text()

                links.push({
                    herf,
                    text
                })
            })
        }

        return links
    })


    browser.close()

    console.log(result)
})()